home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / pmake / lst / RCS / lstDupl.c,v < prev    next >
Encoding:
Text File  |  1992-05-19  |  1.7 KB  |  91 lines

  1. head     1.4;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.4
  10. date     88.11.17.20.52.21;  author adam;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @@
  17.  
  18.  
  19.  
  20. 1.4
  21. log
  22. @checked in with -k by kupfer at 92.05.18.17.32.36.
  23. @
  24. text
  25. @/*-
  26.  * listDupl.c --
  27.  *    Duplicate a list. This includes duplicating the individual
  28.  *    elements.
  29.  *
  30.  * Copyright (c) 1988 by the Regents of the University of California
  31.  *
  32.  */
  33. #ifndef lint
  34. static char *rcsid =
  35. "$Id: lstDupl.c,v 1.4 88/11/17 20:52:21 adam Exp $ SPRITE (Berkeley)";
  36. #endif lint
  37.  
  38. #include    "lstInt.h"
  39.  
  40. /*-
  41.  *-----------------------------------------------------------------------
  42.  * Lst_Duplicate --
  43.  *    Duplicate an entire list. If a function to copy a ClientData is
  44.  *    given, the individual client elements will be duplicated as well.
  45.  *
  46.  * Results:
  47.  *    The new Lst structure or NILLST if failure.
  48.  *
  49.  * Side Effects:
  50.  *    A new list is created.
  51.  *-----------------------------------------------------------------------
  52.  */
  53. Lst
  54. Lst_Duplicate (l, copyProc)
  55.     Lst           l;             /* the list to duplicate */
  56.     ClientData      (*copyProc)(); /* A function to duplicate each ClientData */
  57. {
  58.     register Lst     nl;
  59.     register ListNode      ln;
  60.     register List     list = (List)l;
  61.     
  62.     if (!LstValid (l)) {
  63.     return (NILLST);
  64.     }
  65.  
  66.     nl = Lst_Init (list->isCirc);
  67.     if (nl == NILLST) {
  68.     return (NILLST);
  69.     }
  70.  
  71.     ln = list->firstPtr;
  72.     while (ln != NilListNode) {
  73.     if (copyProc != NOCOPY) {
  74.         if (Lst_AtEnd (nl, (*copyProc) (ln->datum)) == FAILURE) {
  75.         return (NILLST);
  76.         }
  77.     } else if (Lst_AtEnd (nl, ln->datum) == FAILURE) {
  78.         return (NILLST);
  79.     }
  80.  
  81.     if (list->isCirc && ln == list->lastPtr) {
  82.         ln = NilListNode;
  83.     } else {
  84.         ln = ln->nextPtr;
  85.     }
  86.     }
  87.     
  88.     return (nl);
  89. }
  90. @
  91.